import request from '/@/utils/request';

/**
 * 动态表格配置管理接口
 */
export function tableConfigApi() {
	return {
		// 保存表格配置
		saveConfig: (data?: object) => {
			return request({
				url: '/table-config/save',
				method: 'post',
				data,
			});
		},
		// 获取表格配置
		getConfig: (params?: object) => {
			return request({
				url: '/table-config/get',
				method: 'get',
				params,
			});
		},
		// 获取配置列表
		getConfigList: (data?: object) => {
			return request({
				url: '/table-config/list',
				method: 'post',
				data,
			});
		},
		// 删除配置
		deleteConfig: (params?: object) => {
			return request({
				url: '/table-config/delete',
				method: 'delete',
				params,
			});
		},
		// 更新配置
		updateConfig: (data?: object) => {
			return request({
				url: '/table-config/update',
				method: 'put',
				data,
			});
		},
	};
}

/**
 * 动态表格数据管理接口
 */
export function dynamicTableApi() {
	return {
		// 获取表格数据
		getTableData: (configName: string, data?: object) => {
			return request({
				url: '/dynamic-table/data',
				method: 'post',
				data: {
					configName,
					...data
				},
			});
		},
		// 添加数据
		addData: (configName: string, data?: object) => {
			return request({
				url: '/dynamic-table/add',
				method: 'post',
				data: {
					configName,
					...data
				},
			});
		},
		// 更新数据
		updateData: (configName: string, data?: object) => {
			return request({
				url: '/dynamic-table/update',
				method: 'put',
				data: {
					configName,
					...data
				},
			});
		},
		// 删除数据
		deleteData: (configName: string, data?: object) => {
			return request({
				url: '/dynamic-table/delete',
				method: 'delete',
				data: {
					configName,
					...data
				},
			});
		},
		// 获取选项数据（用于下拉框等）
		getOptions: (configName: string, fieldName: string) => {
			return request({
				url: '/dynamic-table/options',
				method: 'get',
				params: {
					configName,
					fieldName
				},
			});
		},
		// 获取数据权限
		getDataPrivilege: (data?: object) => {
			return request({
				url: '/dynamic-table/privilege/get',
				method: 'post',
				data,
			});
		},
		// 绑定数据权限
		bindDataPrivilege: (data?: object) => {
			return request({
				url: '/dynamic-table/privilege/bind',
				method: 'post',
				data,
			});
		},
	};
}